package com.happyfamily.springboot.crowdsourcingplatform.service.guo.impl;
import com.happyfamily.springboot.crowdsourcingplatform.dao.guo.FriendShipDao;
import com.happyfamily.springboot.crowdsourcingplatform.model.*;
import com.happyfamily.springboot.crowdsourcingplatform.service.guo.FriendService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional

public class FriendServiceImpl implements FriendService
{

	@Autowired(required = false)
	FriendShipDao friendShipDao;


	@Override
	public int totalFriend(String ftitle)
	{
		return friendShipDao.getFriendListCount(ftitle);
	}

	@Override
	public List<FriendshipLink> searchFriend(RowBounds rowBounds, String ftitle)
	{
		return friendShipDao.getFriendList(rowBounds,ftitle);
	}

	@Override
	public List<FriendshipLink> getFrontFriendShip()
	{
		return friendShipDao.getFriendListFront("展示");
	}

	@Override
	public String changeTypeBuFid(Long fid)
	{
		String str="";

		List<FriendshipLink> friendshipLinks=friendShipDao.getFriendListFront("展示");
		if (friendshipLinks.size()<15){
			int n=friendShipDao.changeTypeBuFid("展示",fid);
			if (n>0){
				str="yes";
			}else{
				str="no";
			}
		}else{
			str="no";
		}
		return  str;
	}

	@Override
	public String changeTypeBuFidClose(Long fid)
	{
		String str="";
		int n=friendShipDao.changeTypeBuFid("未展示",fid);
		if (n>0){
			str="yes";
		}else{
			str="no";
		}
		return str;
	}

	@Override
	public String changeTypeBuFidDelete(Long fid)
	{

		String str="";
		int n=friendShipDao.changeTypeBuFidDelete(fid);
		if (n>0){
			str="yes";
		}else{
			str="no";
		}
		return str;
	}

	@Override
	public FriendshipLink getInfoFriendLink(Long fid)
	{
		return friendShipDao.getInfoFriendLink(fid);
	}

	@Override
	public String changeTypeBuFidUpdate(String ftitle, String furl, Long fid)
	{
		String str="";
		int n=friendShipDao.changeTypeBuFidUpdate(ftitle,furl,fid);
		if (n>0){
			str="yes";
		}else{
			str="no";
		}
		return str;
	}
}
